package com.alvinlkk.basic.chapter21;


class DualSynch {
    private Object syncObject = new Object();
    
    public synchronized void f() {
        for(int i = 0; i < 5; i ++) {
            System.out.println("f()");
            Thread.yield();
        }
    }
    
    public void g() {
        synchronized (syncObject) {
            for(int i = 0; i < 5; i ++) {
                System.out.println("g()");
                Thread.yield();
            }
        }
    }
}

public class SyncObject {
    public static void main(String[] args) {
        final DualSynch dSynch = new DualSynch();
        new Thread() {
            public void run() {
                dSynch.f();
            };
        }.start();
        dSynch.g();
    }
}
